package config

import (
	"fmt"
	"github.com/jinzhu/configor"
	"log"
	"os"
	"path/filepath"
	"time"
)

var AppConfig = struct {
	App struct {
		Name        string `json:"name"`
		Description string `json:"description"`
		Version     string `json:"version"`
		ApiPrefix   string `json:"api_prefix"`
	}
	Server struct {
		Port         string
		ReadTimeout  time.Duration
		WriteTimeout time.Duration
	}
	Jwt struct {
		SecretKey string
		Timeout   int64
	}
	Db struct {
		Username string
		Password string
		Host     string
		Port     string
		DbName   string
	}
	Static struct {
		StaticPath string
		StaticDir  string
		CacheDir  string
	}
	Mail struct {
		User     string
		Password string
		Host     string
		Port     string
	}
	Miniapp struct{
		Appid string
		Secret string
	}
}{}

func init() {
	var err error
	dir, _ := os.Getwd()
	yamlFile := filepath.Join(dir, "config.yaml")
	err = configor.Load(&AppConfig, yamlFile)
	if err != nil {
		log.Fatalf("Fail to parse 'config/config.yml': %v", err)
	}
	fmt.Println("*********************配置加载成功*********************")
}
